package com.bdtop.dbl;

import android.app.Activity;
import android.app.Fragment;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ZoomControls;

import com.baidu.mapapi.map.MapView;

public class BaseFragment extends Fragment {

	protected String TAG;
	protected BaseActivity holder;
	protected LayoutInflater mInflater;

	protected boolean isHidden;

	protected Handler mHandler;

	protected String loginSign;

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);

		TAG = this.getClass().getSimpleName();
		holder = (BaseActivity) activity;
		mInflater = holder.mInflater;

		mHandler = holder.mHandler;
		loginSign = holder.loginSign;

	}

	public void setAndShowWaitingMessage(int resId) {
		if (holder != null) {
			setAndShowWaitingMessage(getString(resId));
		}
	}

	public void setAndShowWaitingMessage(String resId) {
		if (holder != null) {
			holder.setAndShowWaitingMessage(resId);
		}
	}

	public void clearAndHiddenWaitingMessage() {
		if (holder != null) {
			holder.clearAndHiddenWaitingMessage();
		}
	}

	public void hiddenWaitingMessage() {
		if (holder != null) {
			holder.hiddenWaitingMessage();
		}
	}

	public void showWaitingMessage() {
		if (holder != null) {
			holder.showWaitingMessage();
		}
	}

	public void showToast(String text) {
		if (holder != null) {
			holder.showToast(text);
		}
	}

	public void showToast(int id) {
		if (holder != null) {
			holder.showToast(id);
		}
	}

	public void setTitleText(int resId) {
		if (holder != null) {
			holder.setTitleText(resId);
		}
	}

	public void hideBaiDuZoomController(MapView mMapView) {
		int count = mMapView.getChildCount();
		View zoomView = null;

		for (int i = 0; i < count; i++) {
			View child = mMapView.getChildAt(i);
			if (child instanceof ZoomControls) {
				zoomView = child;
				break;
			}
		}
		zoomView.setVisibility(View.GONE);
	}

	@Override
	public void onHiddenChanged(boolean hidden) {
		super.onHiddenChanged(hidden);
		isHidden = hidden;
	}

	@Override
	public void onDetach() {
		super.onDetach();
		holder = null;
	}

	// public boolean isVisitorMode() {
	// if (isVisitorMode) {
	// ConfirmDialog c = new ConfirmDialog(holder,
	// getString(R.string.hint_tourists),
	// false, getString(R.string.ok));
	// c.show(false);
	// }
	// return isVisitorMode;
	// }

}
